package org.cargloss.cp.controller.users;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.cargloss.cp.controller.modul.PageController;

import util.menu.SubMenu;



import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;



public class AdminAction extends ActionSupport {

	private List<SubMenu> listSubMenu;
	private boolean subMenu;
	private String nav;
	private static final long serialVersionUID = 3107220959703009022L;
	PageController pageControl = new PageController();

	public String execute() {
		return SUCCESS;
	}

	public String home() {
		pageControl.setAll(true);
		Map<String, Object> sessionMap = ActionContext.getContext()
				.getSession();
		int userLevel = (Integer) sessionMap.get("userLevel");
		if (userLevel == 0)
			su();
		if (userLevel == 1)
			admin();
		return SUCCESS;

	}

	private void su() {
		subMenu = true;
		listSubMenu = new ArrayList<SubMenu>();
		setNav("Admin > Manage Menu");
		listSubMenu.add(new SubMenu("Pengguna", "modul/user.action"));
		listSubMenu.add(new SubMenu("Logout", "logout"));
	}

	private void admin() {
		subMenu = true;
		listSubMenu = new ArrayList<SubMenu>();
		setNav("Admin > Manage Menu");
		SubMenu s1 = new SubMenu("Kelompok Pengguna", "modul/kelompokpengguna");
		SubMenu s2 = new SubMenu("Pengguna", "modul/penggunasistem");
		listSubMenu.add(s1);
		listSubMenu.add(s2);

	}

	public boolean isSubMenu() {
		return subMenu;
	}

	public void setSubMenu(boolean subMenu) {
		this.subMenu = subMenu;
	}

	public String getNav() {
		return nav;
	}

	public void setNav(String nav) {
		this.nav = nav;
	}

	public List<SubMenu> getListSubMenu() {
		return listSubMenu;
	}

	public void setListSubMenu(List<SubMenu> listSubMenu) {
		this.listSubMenu = listSubMenu;
	}

	public PageController getPageControl() {
		return pageControl;
	}

	public void setPageControl(PageController pageControl) {
		this.pageControl = pageControl;
	}

}
